/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package com.esm.pdawms.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.esm.pdawms.R;
import com.esm.pdawms.database.manager.SystemCenter;
import com.esm.pdawms.model.Churukuhp;
import com.esm.pdawms.model.Linliaohp;

import java.util.ArrayList;

import zuo.biao.library.base.BaseView;
import zuo.biao.library.model.Entry;
import zuo.biao.library.util.StringUtil;

public class ChurukudanView extends BaseView<Entry<Integer, String>> {
    private static final String TAG = "ChurukudanView";

    public ChurukudanView(Activity context, ViewGroup parent) {
        super(context, R.layout.churuku_view, parent);
    }

    public TextView tv_hpname;
    public TextView tv_kw;
    public TextView tv_num;
    public TextView tv_fnum;

    @Override
    public View createView() {
        tv_hpname = findView(R.id.tv_hpname);
        tv_kw = findView(R.id.tv_kw);
        tv_num = findView(R.id.tv_num);
        tv_fnum = findView(R.id.tv_fnum);
        return super.createView();
    }

    @Override
    public void bindView(Entry<Integer, String> data_) {
        super.bindView(data_ != null ? data_ : new Entry<Integer, String>());
        itemView.setBackgroundResource(selected ? R.drawable.alpha3 : R.drawable.white_to_alpha);
        int index = data.getKey();
        ArrayList<Churukuhp> churukuhpList = SystemCenter.getInstance().churukuhpList;
        if (index < churukuhpList.size()) {
            Churukuhp hk = churukuhpList.get(index);
            String type = hk.getType();
            String hpname = hk.getHpname();
            if (hpname.length() > 10) {
                hpname = hpname.substring(0, 9) + "...";
            }

            //类型:0=半成品入库,1=成品缴库单,2=半成品出库,3=成品销货单,4=生产退料单,5=生产补料单,6=非生产退料单,7=非生产补料单,
            // 8=生产领料单,9=非生产领料单,10=借出单,11=借还入单,12=库存调拨入库单,13=库存调拨出库单,14=库存调整入库单,
            // 15=库存调整出库单,16=销货退回入库单
            if (type.compareToIgnoreCase("2") == 0 || type.compareToIgnoreCase("3") == 0 || type.compareToIgnoreCase("5") == 0
                    || type.compareToIgnoreCase("7") == 0 || type.compareToIgnoreCase("8") == 0 || type.compareToIgnoreCase("9") == 0
                    || type.compareToIgnoreCase("10") == 0 || type.compareToIgnoreCase("13") == 0
                    || type.compareToIgnoreCase("15") == 0 || type.compareToIgnoreCase("17") == 0) {
                //出库
                tv_hpname.setText(hk.getHpcode() + "\n" + hpname + "\n批号：" + hk.getPh());
                tv_num.setText(hk.getNum() + "");
            } else {
                //入库
                tv_hpname.setText(hk.getHpcode() + "\n" + hpname + "\n待检数：" + hk.getNum()+ "\n批号：" + hk.getPh());
                tv_num.setText(hk.getHegenum() + "");

                if (hk.getHegenum() > 0) {
                    tv_num.setTextColor(context.getResources().getColor(R.color.green));
                } else {
                    tv_num.setTextColor(context.getResources().getColor(R.color.black));
                }
            }

            tv_kw.setText(hk.getKwbh());
            tv_fnum.setText(hk.getFnum() + "");
        }
    }

}
